{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import os\n",
    "os.chdir(\"E:\\pythonstudy\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "============ ATM取款系统 ============\n",
      "请登录：\n",
      "账号：a\n",
      "密码：234\n",
      "用户名或密码错误\n"
     ]
    }
   ],
   "source": [
    "\n",
    "info={\"a\":[123,100],\"b\":[456,200],\"c\":[789,300]}#初始化变量，索引值为用户名，123、456、789为密码，100-300为余额\n",
    "\n",
    "print(\"=\"*12,\"ATM取款系统\",\"=\"*12)\n",
    "print(\"请登录：\")\n",
    "name=input(\"账号：\")\n",
    "passwd=int(input(\"密码：\"))#输入账号密码进行登录\n",
    "\n",
    "if info[name][0]==passwd:#登录，如果用户和密码一致，登录成功\n",
    "    print(\"登录成功\")\n",
    "    print(\"{0:1}{1:11}{2:15}\".format(\" \",\"1.查询余额\",\"2.存钱\"))\n",
    "    print(\"{0:1}{1:13}{2:15}\".format(\" \",\"3.取钱\",\"4.退出\"))\n",
    "    while True:\n",
    "        key=int(input(\"请输入对应的操作：\"))\n",
    "        \n",
    "        #查询余额\n",
    "        if key==1:\n",
    "            print(\"=\"*12,\"查询余额\",\"=\"*12)\n",
    "            print(\"您的余额为{}元\".format(info[name][1]))\n",
    "            \n",
    "        #存钱\n",
    "        if key==2:\n",
    "            print(\"=\"*12,\"存钱\",\"=\"*12)\n",
    "            new_add=float(input(\"请输入存款金额：\"))\n",
    "            if new_add<=0:#如果输入的数小于0\n",
    "                print(\"输入错误，请重新输入\")\n",
    "            else:\n",
    "                info[name][1]+=new_add\n",
    "\n",
    "            print(\"您的余额为{}元\".format(info[name][1]))\n",
    "            \n",
    "        #取钱\n",
    "        if key==3:\n",
    "            print(\"=\"*12,\"取钱\",\"=\"*12)\n",
    "            new_add=float(input(\"请输入存款金额：\"))\n",
    "            if new_add>info[name][1]:\n",
    "                print(\"输入错误，请重新输入\")\n",
    "            else:\n",
    "                info[name][1]-=new_add\n",
    "            print(\"您的余额为{}元\".format(info[name][1]))\n",
    "        if key==4:\n",
    "            print(\"=\"*12,\"退出\",\"=\"*12)\n",
    "            break       \n",
    "elif name not in info.keys():\n",
    "    print(\"用户名或密码错误\")\n",
    "else:\n",
    "    print(\"用户名或密码错误\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
